<template>
  <div>
    <el-row>
      <el-button
        plain
        size="mini"
        type="primary"
        icon="el-icon-refresh-left"
        @click="openData()"
        >刷新</el-button
      >
      <el-button
        icon="el-icon-circle-plus-outline"
        type="warning"
        plain
        size="mini"
        @click="addLsh()"
        :disabled="!zIsOpenData"
        >增加流水号配置</el-button
      >
      <el-button
        icon="el-icon-refresh"
        type="danger"
        plain
        size="mini"
        @click="initLshManage()"
        >刷新中间件流水号配置</el-button
      >
      <el-dialog
        v-model="FIsShowEdit"
        width="800PX"
        center
        destroy-on-close
        title="流水号编辑"
      >
        <el-form :model="FIndexLsh" label-position="left" label-width="120px">
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="配置代码">
                <el-input
                  v-model="FIndexLsh.FLshCode"
                  placeholder="请输入流水号配置代码"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="标签说明">
                <el-input v-model="FIndexLsh.FLshCaption"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="流水号头部">
                <el-input
                  v-model="FIndexLsh.FLshHead"
                  placeholder="组成流水号的头部"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="流水号时间格式">
                <el-input
                  v-model="FIndexLsh.FLshDateFormat"
                  placeholder="组成流水号中间部份"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="流水号序号长度">
                <el-input
                  v-model="FIndexLsh.FLshPrecision"
                  placeholder="组成流水号序号"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="目前最大流水号">
                <el-input
                  v-model="FIndexLsh.FLshMaxNumber"
                  readonly
                  ReadOnlyColor
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="启用">
                <el-switch
                  v-model="FIndexLsh.FIsUse"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                >
                </el-switch>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="备注">
            <el-input v-model="FIndexLsh.FLshRemark"></el-input>
          </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="FIsShowEdit = false">取 消</el-button>
            <el-button type="primary" @click="saveLsh()">保存</el-button>
          </span>
        </template>
      </el-dialog>
    </el-row>
    <el-table
      :data="FLshList"
      style="width: 100%; margin-top: 10px; margin-bottom: 20px"
      row-key="FLshID"
      border
      highlight-current-row
    >
      <el-table-column prop="FLshCode" label="配置代码"> </el-table-column>
      <el-table-column prop="FLshCaption" label="配置标签"> </el-table-column>
      <el-table-column prop="FLshHead" label="头部标识"></el-table-column>
      <el-table-column prop="FLshDateFormat" label="时间格式">
      </el-table-column>
      <el-table-column prop="FLshPrecision" label="流水号位数">
      </el-table-column>
      <el-table-column prop="FLshMaxNumber" label="当前最大流水号">
      </el-table-column>
      <el-table-column prop="FIsUse" label="启用">
        <template #default="scope">
          <el-switch
            v-model="scope.row.FIsUse"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column prop="FLshRemark" label="备注"> </el-table-column>
      <el-table-column label="操作" width="200px">
        <template #default="scope">
          <el-button
            type="primary"
            plain
            size="mini"
            @click="editLsh(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script  lang="ts">
import { Options, Vue } from "vue-class-component";
import TFormBase from "@/views/BaseForm";
import { TBaseLsh } from "@/baselib/right/BaseRightClass";
//配合着用
@Options({
  name: "TFormLshList",
  components: {},
  computed: {},
  data() {},
})
export default class TFormLshList extends TFormBase {
  private FIsShowEdit: Boolean = false;
  private FIndexLsh: TBaseLsh = new TBaseLsh();
  private FLshList: TBaseLsh[] = [];
  public created() {
    this.openData();
  }
  //打开数据
  private async openData() {
    this.zIsOpenData = false;
    let lResult = await this.$myBaseRightAPI.GetLshList();
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FLshList = lResult.resultData;
    this.zIsOpenData = true;
    this.$myMsgHelp.msgHintAutoClose(
      "获取数据成功",
      this.$myMsgHelp.msgSuccess
    );
  }
  private addLsh() {
    this.FIndexLsh = new TBaseLsh();
    this.FIsShowEdit = true;
  }
  private editLsh(qBaseLsh: TBaseLsh) {
    this.FIndexLsh = qBaseLsh;
    this.FIsShowEdit = true;
  }
  private async saveLsh() {
    let lResult = await this.$myBaseRightAPI.SaveLsh(this.FIndexLsh);
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FIsShowEdit = false;
    this.openData();
  }
  private async initLshManage() {
    let lResult = await this.$myBaseRightAPI.InitLshManage();
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.$myMsgHelp.msgHintAutoClose("刷新配置成功");
  }
}
</script>